/*
 * Copyright (c) 2018-2024 北京华恒盛世科技有限公司
 * QUICKPOOL is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *     http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
*/

#ifndef QUICKPOOL_EE_H
#define QUICKPOOL_EE_H

#include "common.h"
#include "xdrbase.h"
#include "channel.h"
#include "quickpool.h"
#include "api.h"

#define closesocket close

extern char *gstrMyName;
extern struct task *gptrTasks;
extern int gintNumTask;
extern JOBID_T gintExecJobId;

extern bool_t gboolJobMode;
extern bool_t gboolTaskMode;
extern int gintExecFlag;
#define JM_FLAG_STDIN  0x1
#define JM_FLAG_STDOUT 0x2
#define JM_FLAG_STDERR 0x4
 
extern char child_ee;
extern char child_go;

extern int debug;

typedef enum {
    DEBUG_EE,
    TIMEDEBUG_EE,
} eeparams_t;

struct executeCommand {
    int options;
    char cwd[PATH_MAX+1];
    char **argv;
};

struct task {
    pid_t pid;
    pid_t pgid;
    int exec_option;
    STATUS_WAIT_T wait;
    int exit_code;
    struct jobResourceUsage *inst_usage;
    time_t start_time;
    time_t end_time;
    char *cwd;
};

extern struct config_param eeParams[];

extern void ee_quit(int);

extern void ee_executejob(char **);
extern void log_job_acct(int, struct task *);

extern int kill_mytask(int);
extern void dump_task(struct task *, int, const char *);

extern void handle_file_copy(int , struct header *, XDR *, struct auth *);
extern void handle_task_status(int , struct header *, XDR *);

#endif
